//package com.treasure.mall.zbqmallapi.aspect;
//
//import com.alibaba.fastjson.JSON;
//import com.treasure.mall.biz.entity.user.UserPO;
//import com.treasure.mall.biz.service.core.user.UserService;
//import com.treasure.mall.zbq.common.base.ApiResult;
//import com.treasure.mall.zbq.common.base.ResultCodeEnum;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.PrintWriter;
///**
// * 
// * +---------------------------------------------------------
// * * @package: com.treasure.mall.zbqmallapi.aspect
// * * @author: guomw (guomwchen@foxmail.com)
// * * @date: 2020/7/10 16:40
// * * @since: V1.0.0
// * +---------------------------------------------------------
// * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的
// * Copyright 2019-2022 com.treasure.mall.zbqmallapi.aspect Inc. All rights reserved.
// */
//public class ApiInterceptor implements HandlerInterceptor {
//    @Autowired
//    private UserService userService;
//
//    public UserPO getUser(HttpServletRequest request) {
//        String token = request.getHeader("X-token");
//        if (StringUtils.isNotBlank(token)) {
//            UserPO user = userService.findByToken(token);
//            if (user != null && user.getLoginToken().equals(token)) {
//                return user;
//            }
//        }
//        return null;
//    }
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
//        UserPO user = getUser(request);
//        if (user == null) {
//            PrintWriter out = null;
//            try {
//                response.setCharacterEncoding("UTF-8");
//                response.setContentType("application/json; charset=utf-8");
//                out = response.getWriter();
//                out.append(JSON.toJSONString(ApiResult.errorWith(ResultCodeEnum.NOT_LOGIN)));
//            } finally {
//                if (out != null) {
//                    out.close();
//                }
//            }
//            return false;
//        }
//        return true;
//    }
//
//    @Override
//    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
//
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
//
//    }
//}
